using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace hibou2
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        CreatingA2DSprite.Wizard mWizardSprite;
        hibou.Sprite2 test;
      

        //Create a Horizontally scrolling background
        Background mScrollingBackground;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            if (Keyboard.GetState().IsKeyDown(Keys.Q))
            {

                this.graphics.ToggleFullScreen();
            }
            else
            {
                this.graphics.PreferredBackBufferHeight = 500;
                this.graphics.PreferredBackBufferWidth = 800;
            }
                      
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            mWizardSprite = new CreatingA2DSprite.Wizard();
            test = new hibou.Sprite2(new Vector2(0, 460));
            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            mWizardSprite.LoadContent(this.Content);
            test.LoadContent(Content, "mur");
            
            //Initialize and add the background images to the Scrolling background. You can change the
            //scroll area by passing in a different Viewport. The images will then scale and scroll within
            //that given Viewport.
            mScrollingBackground = new Background(this.GraphicsDevice.Viewport);
            mScrollingBackground.AddBackground("back1");
            mScrollingBackground.AddBackground("back1");
            mScrollingBackground.AddBackground("back1");
            mScrollingBackground.AddBackground("back1");
            mScrollingBackground.AddBackground("back1");

            //Load the content for the Scrolling background
            mScrollingBackground.LoadContent(this.Content);
                    }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            KeyboardState KState = Keyboard.GetState();
            this.Window.Title = "hibou l'hero du jour";
            foreach (Keys key in KState.GetPressedKeys())
                this.Window.Title += key.ToString();
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                this.Exit();
            
            //Update the scrolling backround. You can scroll to the left or to the right by changing the scroll direction
            mScrollingBackground.Update(gameTime, 160, Background.HorizontalScrollDirection.Left);

            mWizardSprite.Update(gameTime);
            if (Keyboard.GetState().IsKeyDown(Keys.Q))
            {
                
                this.graphics.ToggleFullScreen();
            }
            else
            {
                this.graphics.PreferredBackBufferHeight = 500;
                this.graphics.PreferredBackBufferWidth = 800;
            }

            test.Update(new Vector2(0, 0));


            
        
            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin();
            //Draw the scrolling background
            mScrollingBackground.Draw(spriteBatch);
            mWizardSprite.Draw(this.spriteBatch);
            test.Draw(spriteBatch);
            spriteBatch.End();

            base.Draw(gameTime);
        }

        public float mechelle { get; set; }
    }
}
